Learn how to integrate Algolia into your Salesforce Commerce Cloud PWA Kit project.
@salesforce/retail-react-app
repository as a base template and include only the overridden or customized files from the original template.
You can selectively incorporate the relevant files or changes into your repositories or use the entire demo repository as starter code for your project.
For more information about template extensibility in the Salesforce PWA Kit, refer to the Salesforce documentation.
@salesforce/retail-react-app
version 3.0.1
.
If you use a different version, some configurations may differ.
Check the changelog for your specific version to see any relevant changes.
color
, size
, colorVariations
, masterID
, lsImage
, short_description
, long_description
, pricebooks
, brand
, name
, in_stock
as Additional Product Attributes
in the custom preferences.
If you’re using other datasets or a custom indexing approach, adjust your implementation accordingly.algolia-config.json
file in your config
folder or use and rename the example file, then update the Algolia app credentials and indices in it.
commerce-api-config.json
file in your config
folder or use and rename the example file, then update the Salesforce Commerce Cloud API credentials in it.
PWA_KIT_SLAS_CLIENT_SECRET
in your environment variables.
localhost:3000
using the default Algolia app credentials in the algolia-config.json
file.
algolia-config.json
file in your root folder or use and rename the example file.
babel.config.js
and postcss.config.js
files from the demo repository to your project’s root directory.
overrides/app/components/algolia
directory from the demo repository to your project.
overrides/app/route.jsx
file to include the Algolia product list and detail pages:
productDetail
page now showcases recommendation widgets. If the
recommendation widgets on the product detail page aren’t required, you can
remove the ProductDetail
component as necessary.algolia-config.json
fileappId
: your Algolia application ID, which you can find in the Algolia dashboardapiKey
: your Algolia API key, which you can find in the Algolia dashboardindices.querySuggestions
: the Query Suggestions index nameindices.primary.label
: the label for the default sorting optionindices.primary.value
: the primary product index nameindices.replicas
: a sorting options array and their corresponding index namesindices.contents
: the content index nameindices.faq
: the FAQ index name.
You can use a specific index; the content index serves demonstration purposes.indices.categories
: the categories index name.algolia-product-list
page for the /search
and /category/:categoryId
routes.
It uses the following npm packages for building the InstantSearch experience:
InstantSearch in the demo provides the following features:
hierarchicalCategoryAttributes
, and filterEls
variables in the overrides/app/pages/algolia-product-list/index.jsx
file.
For example, to use a different refinement like “collection” instead of “brand”, update the AlgoliaCheckboxRefinements
attributes:
AlgoliaCheckboxRefinements
component with necessary attributes in the filterEls
.
overrides/app/pages/algolia-product-list/index.jsx
file and the components inside the overrides/app/pages/algolia-product-list/partials
directory, as well as the complete InstantSearch documentation.
overrides/app/components/algolia/autocomplete
directory.
The main file for the Autocomplete implementation is overrides/app/components/algolia/autocomplete/index.jsx
.
It imports various plugins and components to create a feature-rich autocomplete experience.
The Autocomplete component uses the following plugins:
recentSearchesPlugin
createLocalStorageRecentSearchesPlugin
.
The plugin stores recent searches in the browser’s local storage under the key ‘pwa-recent-searches’.
querySuggestionsPlugin
createQuerySuggestionsPlugin
and fetches suggestions from the indices.querySuggestions
index in the configuration.
categoriesPlugin
getAlgoliaResults
function to retrieve category results from the indices.categories
index in the configuration.
brandsPlugin
getAlgoliaFacets
function to fetch trending brands from the indices.primary.value
index in the configuration.
faqPlugin
algolia.indices.faq
index using the getAlgoliaResults
function.
popularPlugin
createQuerySuggestionsPlugin
to retrieve popular searches from the indices.querySuggestions
index in the configuration.
popularCategoriesPlugin
getAlgoliaFacets
function to retrieve popular categories from the indices.primary.value
index in the configuration.
productPlugin
getAlgoliaResults
function to retrieve product results from the indices.primary.value
index in the configuration.
popularCategoriesPlugin
helps display popular product categories based on search results.
It uses hardcoded images.
Change them in the file popularCategoriesPlugin.tsx
.
The QuickAccessPlugin
showcases Rules and always returns the same result that depends on the rule configuration.
The overrides/app/components/algolia/autocomplete/plugins/quickAccessPlugin.tsx
file includes an example configuration.
The RecentSearchesPlugin
uses local storage for each user.
For demonstration purposes, the overrides/app/components/algolia/autocomplete/index.jsx
file includes sample data.
The overrides/app/components/algolia/style.css
file includes all the styles for Algolia components.
You can customize the styles according to your design requirements.
These plugins work together to provide a comprehensive autocomplete experience, offering suggestions for recent searches, query suggestions, categories, brands, FAQs, popular searches, popular categories, and products.
overrides/app/components/algolia/recommend
directory.
The available Recommend components are:
FrequentlyBoughtTogether
: displays products frequently bought with the current productLookingSimilar
: shows products that look like the current productRelatedProducts
: displays products with similar attributes as the current productTrendingItems
: displays trending products (based on a specific facet name and facet values).TrendingFacets
: shows trending facet values for a facet name.@algolia/recommend-react
package to fetch recommendations from Algolia.
The following are examples of the Recommend components.
Import them from the overrides/app/components/algolia/recommend
directory for use anywhere in your project.
FrequentlyBoughtTogether:
FrequentlyBoughtTogether
, RelatedProducts
, and LookingSimilar
components in the overrides/app/pages/algolia-product-detail/index.jsx
file.
In the preceding examples:
product
represents the current product object for displaying recommendations.
It’s like the context-object
in Einstein Recommendation isslots
.facetName
and facetValue
specify the facet name and value for fetching trending items.recommendClient
to specify the Algolia Recommend clientindexName
to specify the index to fetch recommendations fromheaderComponent
and itemComponent
for rendering custom headers and items.overrides/app/components/algolia/recommend
directory.
overrides/app/components/algolia/autocomplete/plugins/popularCategoriesPlugin.tsx
Problem | Solution |
---|---|
Index not found | Check if you have created the index and pointed to it in the algolia-config.json file. |
Recommend model not found | Train the model for the corresponding index |
Query Suggestions not found | Create a Query Suggestions index and point to it in the algolia-config.json file |
Quick View section doesn’t work | Create a rule with the appropriate data |
Broken page when clicking a product tile | Set the isPWA hardcoded variable to true in the modelHelper.js file. |
Broken color codes | Update or add missing color codes in cssColorGroups in the overrides/app/constants.js file |